#ifndef GHOSTINGGRAPHICSOBJECT_H
#define GHOSTINGGRAPHICSOBJECT_H

#include <QGraphicsScene>
#include <QGraphicsObject>
#include <QGraphicsSceneMouseEvent>
#include <QPixmap>
#include <QImage>
#include <QBitmap>
#include <QDebug>
#include <QTimer>
#include <QColor>
#include <QPropertyAnimation>
#include "gs.h"

#define COLOR0 255,0,0
#define COLOR1 255,0,255
#define COLOR2 0,255,255
#define COLOR3 0,255,0
#define COLOR4 255,255,0

using namespace gs;

namespace gs
{

// users could create cut scenes from individual classes,
// or get one instance from the cut scene manager
class CutSceneManager : public QObject
{
    Q_OBJECT
public:
    static void initialize( QGraphicsScene * );
    static GhostingGraphicsObject * getGhosting();
protected:
    explicit CutSceneManager( QObject * parent = 0 );
    static CutSceneManager * csmanager;
    static bool initialized;
    static QGraphicsScene * scene;
private:
};



class GhostingGraphicsObject : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit GhostingGraphicsObject(QGraphicsItem *parent = 0);
    void setPixmap( QString string = QString( ":/common/images/ranger.png" ), bool colorized = true );
    void setDuration( int show, int fade ) { dur_show = show; dur_hide = fade; }
    void setStartEnd( QPointF, QPointF, bool dynamicOpacity = true );
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * );
    QRectF boundingRect () const
    {
        return QRectF( -width/2, -height/2, width, height );
    }
signals:
    void ready();
public slots:
    void updateAnimation();
    void animate();
    void updateScene()
    {
        update();
    }
protected:
    //void mousePressEvent(QGraphicsSceneMouseEvent *);
    const static int width = 1400, height = 800;
    QColor colors[5];
    QPixmap pixmap, mypixmap[5], pmbg;
    QPointF poses[7], offset, pos_start, pos_end;
    QImage  image;
    QTimer* timer;
    qreal init_dist, opac;
    int dur_show, dur_hide;
    bool  dynamicOpacity;
    QPropertyAnimation * hide_anim;
};
}
#endif // GHOSTINGGRAPHICSOBJECT_H
